package business.view;

import java.io.File;
import java.io.FileInputStream;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.ArrayList;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamSource;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

import business.bl.CandidatoBL;

public class CandidatoListRenderer {
	
	private String xmlInput="";
	private String xslPath="";
	public static Logger logger = LogManager.getLogger(CandidatoListRenderer.class);
	
	public CandidatoListRenderer(String xmlInput,String xslPath) {
		super();
		this.xmlInput = xmlInput;
		this.xslPath=xslPath;
	}

	public String getHtml(){
		String result="";
		try {
		    StringReader reader = new StringReader(xmlInput);
		    StringWriter writer = new StringWriter();
		    
		    TransformerFactory tFactory = TransformerFactory.newInstance();
		    Transformer transformer = tFactory.newTransformer(
		            new javax.xml.transform.stream.StreamSource(xslPath));
		    

		    transformer.transform(
		            new javax.xml.transform.stream.StreamSource(reader), 
		            new javax.xml.transform.stream.StreamResult(writer));
		    
		    
		    
		    result = writer.toString();
		    logger.debug(result);
		    

		    
		}catch (Exception e) {
			logger.error("",e);
		}
		return result;
	}
}
